{include file="public/header" /}
<script src="/static/public/ueditor/ueditor.config.js"></script>
<script src="/static/public/ueditor/ueditor.all.min.js"></script>
<script src="/static/public/ueditor/lang/zh-cn/zh-cn.js"></script>
<body>
<div class="x-body ">
    <form  class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">所属栏目</label>
            <div class="layui-input-block">
                <select name="cate_id" lay-verify="required">
                    <option selected disabled>请选择</option>
                    {volist name='cate_list' id='vo'}
                    <option value="{$vo.id}"
                        {if $vo.id == $article.cate_id}
                        selected
                        {/if}
                    ><?php echo str_repeat("-",$vo['level']*3)?>{$vo.cate_name}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="title" class="layui-form-label">文章标题</label>
            <div class="layui-input-inline">
                <input type="text" id="title" name="title" lay-verify="required" value="{$article.title}"  autocomplete="off" class="layui-input" >
                <input type="hidden" id="id" name="id" lay-verify="required" value="{$article.id}"  autocomplete="off" class="layui-input" >
                <input type="hidden" id="yuantu" name="yuantu" value="{$article.thumb}"  autocomplete="off" class="layui-input" >
                <p id="pLog" style="color:red"></p>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否置顶</label>
            <div class="layui-input-block">
                <input type="checkbox"  {if 1==$article.show_top}checked=""{/if}   name="show_top" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
                <div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em>ON</em><i></i></div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">关键词</label>
            <div class="layui-input-block">
                <textarea name="keywords" placeholder="请输入内容" class="layui-textarea">{$article.keywords}</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="description" placeholder="请输入内容" class="layui-textarea">{$article.description}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="author" class="layui-form-label">文章作者</label>
            <div class="layui-input-inline">
                <input type="text" id="author" name="author" lay-verify="required" value="{$article.author}"  autocomplete="off" class="layui-input" >
                <p id="pLog" style="color:red"></p>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="author" class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="text" id="email" name="email"   value="{$article.email}"  autocomplete="off" class="layui-input" >
                <p id="pLog" style="color:red"></p>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="author" class="layui-form-label">外链</label>
            <div class="layui-input-inline">
                <input type="text" id="link_url" name="link_url"  value="{$article.link_url}"   autocomplete="off" class="layui-input" >
                <p id="pLog" style="color:red"></p>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文章封面</label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="upload1">上传图片</button>
                <input type="hidden" id="img_url" name="thumb" value=""/>
                <div class="layui-upload-list">
                    <img class="layui-upload-img"  {if $article.thumb != null} src="<?php echo '/static/uploads/' ?>{$article.thumb}" {/if} width="100px" height="80px" id="demo1"/>
                    <p id="demoText"></p>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">文章内容</label>
            <div class="layui-input-block">
                <textarea name="content" id="content" placeholder="请输入内容" class="layui-textarea">{$article.content}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <button class="layui-btn" lay-submit lay-filter="addId">
                修改
            </button>
        </div>
    </form>
</div>

<script type="text/javascript">
    layui.use('upload', function(){
        var upload = layui.upload
            , $ = layui.jquery;
        var uploadInst = upload.render({
            elem: '#upload1' //绑定元素
            ,url: "{:url('admin/brand/upload')}"
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code === 0){
                    return layer.msg('上传失败');
                }
                //上传成功
                document.getElementById("img_url").value = res.url;

            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
    });
</script>
<script type="text/javascript">
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    UE.getEditor('content',{initialFrameWidth:600,initialFrameHeight:400,});
</script>
<script>
    layui.use(['form'], function(){
        $ = layui.jquery;
        var form = layui.form,layer = layui.layer;
        //监听提交
        form.on('submit(addId)', function(data){
            //console.log(data);
            $.post("{:url('admin/Article/edit')}",data.field,function(info){
                if (info.errorCode===1) {
                    layer.alert("修改成功", {icon: 6},function () {
                        window.parent.location.reload();  //刷新父级页面
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前弹出层
                        parent.layer.close(index);
                    });
                }else{
                    layer.alert(info.msg, {icon: 5});
                }
            },'json');
            return false;
        });
    });
</script>
</body>

</html>